#usr/bin/env python3
#-*- coding:utf-8 -*-
import sys
def rcToAa(S):
    length=len(S)
    count=0
    result=""
    dCount=0
    for i in range(length):
        if S[i]=='C':
            count=i
            pass
        pass

    temp=int(S[(count+1):length])

    while temp>0:
        if temp%26==0:
            result=result+'Z'
            temp=temp//26-1
        else:
            result=result+chr(ord('A')+temp%26-1)
            temp=temp//26
    result = result[::-1] + str(S[1:count])
    return result
    pass

def aaToRc(S):
    length=len(S)
    count=0
    temp=0
    result=[]
    for i in range(length):
        if S[i]>='0' and S[i]<='9':
            count=i
            break
            pass
        pass
    for i in range(count-1):
        temp= (temp+(ord(S[i])-ord('A')+1))*26
        pass
    temp=temp+(ord(S[count-1])-ord('A')+1)
    return 'R'+str(S[count:length])+'C'+str(temp)
    pass

if __name__=='__main__':
    S=[]
    N=int(input())
    for i in range(N):
        S.append(input())
        pass
    for i in range(N):
        temp=S[i]
        if temp[0]=='R' and temp[1].isdigit() and 'C' in temp:
            print(rcToAa(temp))
        else:
            print(aaToRc(temp))